package com.trsj.lnsj.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.trsj.lnsj.common.DataResponse;
import com.trsj.lnsj.service.ICollectionService;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(value = "/api/collection/*")
@CrossOrigin
public class CollectionController {
    private Logger logger = LoggerFactory.getLogger(CollectionController.class);
    @Autowired
    private ICollectionService collectionService;

    /**
     * 
     * @param pageNum
     * @param pageSize
     * @param userId
     * @param type 活动类型
     * @param request
     * @return
     */
    @ApiOperation(value = "获取用户收藏列表", notes = "获取用户收藏列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public DataResponse list(@RequestParam(defaultValue="1") int pageNum, @RequestParam(defaultValue="10") int pageSize, @RequestParam(required=true) long userId, String type, HttpServletRequest request) {
        DataResponse resp = collectionService.queryMyCollection(pageNum,pageSize,userId,type);
        logger.info("resp = {}", resp.getData());
        return resp;
    }

    @ApiOperation(value = "活动收藏", notes = "添加到活动收藏")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public DataResponse add(@RequestParam(required=true)long userId, @RequestParam(required=true)long actId, HttpServletRequest request) {
        DataResponse resp = collectionService.addCollection(userId,actId);
        logger.info("resp = {}", resp);
        return resp;
    }

}
